<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;
use User\Api\UserApi as UserApi;

/**
 * 后台首页控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class ZtglController extends AdminController {

    /**
     * 后台首页
     * @author 麦当苗儿 <zuojiazi@vip.qq.com>
     */
    //业务类别列表
    public function ywlb(){
        $this->meta_title = '业务类别';
        $this->display();
    }
    //业务类别添加
    public function lbadd(){    
        $this->meta_title = '业务添加';
        $this->display('add');
    }
    //业务类别添加
    public function ywadd(){
    	$authgroup = D('AuthGroup')->where(array('description'=>1))->field('id,title')->select();
    	$this->assign('group',$authgroup);
    	$this->meta_title = '业务添加';
    	$this->display('add');
    }

    //渠道类别列表
    public function qdlb(){
        $this->meta_title = '渠道类别';
        $this->display();
    }
    //渠道状态添加
    public function qdadd(){	
    	$this->meta_title = '渠道添加';
    	$this->display('add');
    }

    //类别状态列表
    public function ywzt(){
        $this->meta_title = '渠道类别';
        $this->display();
    }
    //发单权限列表
    public function fdqx(){
        $this->meta_title = '发单权限';
        $this->display();
    }
	//支付款项列表
    public function zfkx(){
        $this->meta_title = '渠道类别';
        $this->display();
    }
    //支付款项添加
    public function zfkxadd(){	
    	$this->meta_title = '渠道添加';
    	$this->display('add');
    }
    //支付方式列表
    public function zffs(){
        $this->meta_title = '渠道类别';
        $this->display();
    }
    //支付方式添加
    public function zffsadd(){	
    	$this->meta_title = '渠道添加';
    	$this->display('add');
    }
   //客资标签列表
    public function kzbq(){
        $this->meta_title = '客资标签';
        $this->display();
    }
	   //客资标签列表
    public function kzbqadd(){
        $this->meta_title = '客资标签添加';
		$this->display('add');
    }
   

    //公共更新
    public function edit(){
    	$qdedit = M('ywlb');
    	if(IS_POST){
    		$data = array('name'=>I('name'),'sid'=>I('sid'));
    		$res = $qdedit->where(array('uid'=>I('uid')))->save($data);
    		if($res){
    			$this->success('更新成功');
    		}else{
    			$this->error('更新失败');
    		}
    	}
    }
    //共用添加业务状态权限，用户管理职位显示状态所用
    public function add_group(){
        $uid = I('uid');
        if(!I('group_id')){
            $gid['jb'] = 0;
        }else{
            $gid['jb'] = implode(",",I('group_id'));
        }
        if( empty($uid) ){
            $this->error('参数有误');
        }
        $AuthGroup = M('Ywlb');
        if(is_numeric($uid)){
            if( !$AuthGroup->where(array('uid'=>$uid))->find() ){
                $this->error('授权的状态不存在！');
            }
        }

        if ( $AuthGroup->where(array('uid'=>$uid))->save($gid)){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }

    }
    //公共添加
    public function add(){
    	$ywlb = M('ywlb');
        if(!I('group_id')){
            $jb = I('jb');
        }else{
            $jb = implode(",",I('group_id'));
        }

    	if(IS_POST){
    		$data = array('name'=>I('name'),'sid'=>I('sid'),'status'=>1,'lb'=>I('lb'));
    		$res = $ywlb->add($data);
    		if($res){
    			$this->success('添加状态成功！');
    		}else{
    			$this->error('添加失败！');
    		}
    	}   	
    }
    //公共设置状态
    public function setstatus(){
    	 if(IS_GET){
    	 	$data = array('status'=>I('status'));
    	 	$res = M('ywlb')->where(array('uid'=>I('uid')))->save($data);
    	 	if($res){
    			$this->success('更新成功');
    		}else{
    			$this->error('更新失败');
    		}
    	 }
    }

    //公共类别删除
    public function remove(){
    	if(IS_GET){
    	 	$res = M('ywlb')->where(array('uid'=>I('uid')))->delete(); 
    	 	if($res){
    			$this->success('删除成功');
    		}else{
    			$this->error('删除失败');
    		}
    	 }
    	$this->meta_title = '渠道删除';
    }

	//共用数据输出  
    public function tree($tree = null){
       // C('_SYS_GET_CATEGORY_TREE_') || $this->_empty();
    	$ywtree = M('ywlb');
    	$authgroup = D('AuthGroup')->where(array('description'=>1))->field('id,title')->select();

    	if(ACTION_NAME == 'qdlb'){
    		$tree = $ywtree->where(array('lb'=>1))->select();
    	}elseif(ACTION_NAME == 'ywlb'){
    		$tree = $ywtree->where(array('lb'=>2))->select();
    	}elseif(ACTION_NAME == 'ywzt'){
            $tree = $ywtree->where(array('lb'=>3))->select();
    	}elseif(ACTION_NAME == 'zfkx'){
            $tree = $ywtree->where(array('lb'=>4))->select();
        }elseif(ACTION_NAME == 'zffs'){
			$tree = $ywtree->where(array('lb'=>5))->select();
		}elseif(ACTION_NAME == 'kzbq'){
			$tree = $ywtree->where(array('lb'=>6))->select();
		}	

    	
    	$this->assign('group',$authgroup);
        $this->assign('tree', $tree);
        $this->display('tree');
    }
}
